
 <template>
 	<el-dialog title="修改" visible :show-close="false" :modal-append-to-body="false" class="wrap" size="tiny">
    <i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
      <div class="bt">退货编辑</div>
 		<el-form label-width="100px" class="form">
 			<el-form-item label="退货名称">
 				<el-input v-model="form.wpmc"  :readonly="true"  placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 			<el-form-item label="退货单价">
 				<el-input v-model="form.wpdj" :readonly="true"   placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 			<el-form-item label="库存数量">
 				<el-input v-model="form.kcsl" disabled  :readonly="true"  placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 			<el-form-item label="退货数量">
 				<el-input v-model="form.sl"  placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 			<el-form-item label="退货金额">
 				<el-input v-model="thje"  placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 			<el-form-item label="退货原因">
 				<el-input v-model="form.thyy" type="textarea" :rows="4" placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 		</el-form>
 		<el-button type="primary" class="submit" :disabled="jy" @click="submit">修改</el-button>
 		<el-button type="danger" class="submit"  @click="cancel">退出</el-button>
 	</el-dialog>
 </template>
 <script type="text/javascript">
 	import qs from 'qs'
 	export default {
 		props: ['params'],
 		data() {
 			return {
 				form: {
				   wpid :'',
				   wpmc :'',
				//  thje:'',
				   sl :'',
				   thyy :'',
				   wpdj:'',
				   kcsl:'',
 				   id:''
 				},
 				jy:false
 			}
 		},
 		created() {
  		 this.form.id = this.params.row.id;
  		 this.form.wpid = this.params.row.wpid;
          this.loadinfo();
 		},
 		methods: {
 			loadinfo(){
 			var logininfo = JSON.parse(localStorage.logininfo) ;
            var params3 = qs.stringify({
               xxid:logininfo.xxid,
               yhid:logininfo.id,
               id:this.form.id
						});
 			this.axios.post(this.$store.state.api+'wpcgth/info',params3)
         .then( res =>  {
 							this.form=res.data.data
 					 }).catch(res => {
 						 this.$message.warning("服务器异常");
 			 				this.$emit('close', { type: 'info', cancel: true });
 					 })
 			},
 			 submit() {
 				//检测
 				this.$store.state.loading = true;
 				/*if(!this.form.id) {
 					this.$message.warning('请填写分类');
 					this.$store.state.loading = false;
 					return;
 				}*/
 				//装载数据
 				var logininfo = JSON.parse(localStorage.logininfo);
 				var params2 = qs.stringify({
 						id: this.form.id+'',
 						wpid: this.form.wpid+'',
 						sl: this.form.sl+'',
 						thyy: this.form.thyy+'',
 						thje: this.thje+'',
 						yhid: logininfo.id+'',
 						xxid: logininfo.xxid+''
 				})
 				//执行
 				    this.axios.post(this.$store.state.api + 'wpcgth/update',  params2 )
 						.then(res => {
 							if(res.data.code == 1) {
 								this.$emit('close', { type: 'edit', cancel: false });
 								this.$store.state.loading = false;
 							} else {
 							this.$message.warning(res.data.msg);
 								this.$store.state.loading = false;
 							}
 						}).catch(res => {
 							this.$message.warning("服务器异常");
 							this.$store.state.loading = false;
 						})
 			},
 			cancel() {
 				this.$emit('close', { type: 'edit', cancel: true })
 			}
 		},
 		 computed: {
          thje(){
            let number = this.form.wpdj * this.form.sl ;
            if (number<=0) {
              return 0.00
            }else if(number<=this.form.kcsl*this.form.wpdj){
            	this.jy =false
            	return number
            }else{
            	this.$message.warning('输入退货数量有误')
            	this.jy =true
            }
          },
          }
 	}
 </script>
 <style lang="less" scoped>
 .wrap {
 	text-align: center;
 }
 .bt{
 		position: absolute;
 		width: 100%;
 		height: 50px;
 		margin: 0 auto;
 		top: 0;
 		left: 0;
 		background: #50BFFF;
 		color:white;
 		text-align:left;
 		line-height: 50px;
 		font-size: 17px;
 		padding-left: 15px;
 	}

 .form {
 	text-align: left;
 }
  .input {
 					width: 300px;
 					display: inline-block;
 			}

 .select-block {
 	display: block;
 	width: 85%;
 }

 .submit {
 	width: 120px;
 }
 </style>
